package com.tckdq.tcc.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.tckdq.tcc.domain.Invitation;
import com.tckdq.tcc.mapper.InvitationMapper;
import com.tckdq.tcc.service.IInvitationService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author whale
 * @since 2022-08-22
 */
@Service
public class InvitationServiceImpl extends ServiceImpl<InvitationMapper, Invitation> implements IInvitationService {
    @Autowired
    private InvitationMapper InvitationMapper;
    public void save(String invitationCode) {
        Invitation invitation = new Invitation();
        invitation.setCode(invitationCode);
        invitation.setUserId(1L);
        InvitationMapper.insert(invitation);
    }

    @Override
    public void deleteByCode(String invitationCode) {
        EntityWrapper<Invitation> entityWrapper = new EntityWrapper<>();
        entityWrapper.eq("code",invitationCode);
        delete(entityWrapper);
    }

    @Override
    public Invitation selByCode(String invitationCode) {
        EntityWrapper<Invitation> entityWrapper = new EntityWrapper<>();
        entityWrapper.eq("code",invitationCode);
        return selectOne(entityWrapper);
    }
}
